
var ns;
var app = new Vue({
    el: '#app',
    data: {
        UserID:0,
        list: [],
        selectlist:[],
    },
    methods: {
        get_data: function() {
            var that=this;
            var option={};
            option.action="getsysmenuempowerlist";
            option.UserID=that.UserID;
            console.log(JSON.stringify(option));
            ns.post(option, function (succeed, data, err) {
                 console.log(JSON.stringify(err));
                 console.log(JSON.stringify(data));
                 if(succeed){
                     if(data.status){
                         that.list=data.list
                     }else{
                        api.toast({
                            msg: data.msg,
                            duration: 2000,
                            location: 'bottom'
                        });
                     }

                 }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                 }
             });

        },
        
        do_choose: function(item) {
            var that = this;
            item.checked = !item.checked;
            var removeindex = 0;
            for (var i = 0; i < that.selectlist.length; i++) {
                if (that.selectlist[i] == item.id) {
                    removeindex = i;
                }
            }
            if (item.checked) {
                that.selectlist.push(item.id);
            }
            if (!item.checked) {
                that.selectlist.splice(removeindex, 1);
            }

        },
        // 保存授权
        open_savezh:function(){
            var that=this;
            var option={};
            option.UserID=that.UserID;
            option.SysMenuIDList=JSON.stringify(that.selectlist);
            option.action='savesysmenuempower';
            console.log(JSON.stringify(option));
            ns.post(option, function (succeed, data, err){
                console.log(JSON.stringify(err));
                console.log(JSON.stringify(data));
                if(succeed){
                    if(data.status){
                        api.toast({
                            msg: data.msg,
                            duration: 2000,
                            location: 'bottom'
                        });
                        setTimeout(() => {
                            api.closeWin();
                        }, 500);
                    }else{
                       api.toast({
                           msg: data.msg,
                           duration: 2000,
                           location: 'bottom'
                       });
                    }

                }else{
                   api.toast({
                       msg: err,
                       duration: 2000,
                       location: 'bottom'
                   });
                }

            })
           

        },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.UserID = api.pageParam.id;
    app.get_data();
    // app.get_gongneng();
};
